package game.gui;

/**
 * This class represents the Settings window that pops up when a user wants to change
 * the settings of the game.
 * @author Kristen
 */
import java.awt.GridLayout;
import java.awt.event.*;

import game.driver.Controller;
import game.utils.Util;

import javax.swing.*;

public class SettingsGUI extends JFrame implements ActionListener{
	

	private static final long serialVersionUID = -5997006155582575093L;
	
	JPanel langPanel;
	JPanel colorPanel;
	JPanel buttonPanel;

	JLabel language;
	JRadioButton englishButton;
	JRadioButton spanishButton;
	String chosenLang="english";
	
	JLabel color;
	JRadioButton greenButton;
	JRadioButton redButton;
	JRadioButton purpleButton;
	String chosenColor="green";
	
	JButton okayButton;
	Controller controller;
	Board board;

	/**
	 * This is the constructor. It creates a new window for the settings menu.
	 */
	public SettingsGUI(Controller c, Board b){
		super(Util.SETTINGS);
		controller=c;
		board=b;
		setSize(Util.SETTINGS_WINDOW_WIDTH,Util.SETTINGS_WINDOW_HEIGHT);
		setLayout(new GridLayout(3,1));
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setVisible(true);
		addButtons();

	}
	
	/**
	 * This method adds the buttons and labels to the settings window.
	 */
	public void addButtons(){
		englishButton = new JRadioButton(Util.ENGLISH);
		spanishButton = new JRadioButton(Util.SPANISH);
		ButtonGroup langGroup = new ButtonGroup();
		langGroup.add(englishButton);
		langGroup.add(spanishButton);
		language=new JLabel(Util.LANGUAGE +":   ");
		
		langPanel = new JPanel();
		langPanel.add(language);
		langPanel.add(englishButton);
		langPanel.add(spanishButton);
		
		englishButton.addActionListener(this);
		spanishButton.addActionListener(this);
		
		greenButton = new JRadioButton(Util.GREEN);
		redButton = new JRadioButton(Util.RED);
		purpleButton = new JRadioButton(Util.PURPLE);
		ButtonGroup colorGroup = new ButtonGroup();
		colorGroup.add(greenButton);
		colorGroup.add(redButton);
		colorGroup.add(purpleButton);
		color = new JLabel(Util.COLOR +":   ");
		
		colorPanel = new JPanel();
		colorPanel.add(color);
		colorPanel.add(greenButton);
		colorPanel.add(redButton);
		colorPanel.add(purpleButton);
		
		greenButton.addActionListener(this);
		redButton.addActionListener(this);
		purpleButton.addActionListener(this);
		
		okayButton = new JButton(Util.OKAY);
		okayButton.addActionListener(this);
		buttonPanel = new JPanel();
		buttonPanel.add(okayButton);
		
		add(langPanel);
		add(colorPanel);
		add(buttonPanel);
	
	}

	
	/**
	 * This method recognizes when the okay button is pressed and reads which
	 * options have been selected. It then sends to information to the Controller
	 * to change the appropriate settings.
	 */
	public void actionPerformed(ActionEvent a) {
		
		if(a.getActionCommand()==Util.OKAY){
			
			if(englishButton.isSelected())
				chosenLang="english";
			if(spanishButton.isSelected())
				chosenLang="spanish";
			if(greenButton.isSelected())
				chosenColor="green";
			if(redButton.isSelected())
				chosenColor="red";
			if(purpleButton.isSelected())
				chosenColor="purple";
			
			board.updateBoard(chosenLang+" "+chosenColor);
			dispose();
		}
		
	}
	
	
}	
